class People {
  public username!:string
  public age!:number
  public address!:string
  public phone:string
  constructor() {}
  eat() {

  }
  step() {

  }
}

class Stu extends People {
  public username!:string
  public age!:number
  public address!:string
  constructor(username:string, age:number, address:string, public phone:string) {
    super()
  }
  study() {

  }
  
}

let people = new People()
let result = people as Stu // 类型断言 正确
// let result = <Stu>people  // 类型转换言 正确
 // 本来people实例是没有study方法的，但是通过as转换后，result中就有study方法了，继承关系间可以互相断言（转换）， 但注意一般在绝大多数场景下都是把父类的对象变量断言成子类
result.study()

let stu = new Stu('burt', 18, '上海', '123')
stu as People // 正确


/** 多态
 * 父类的对象变量可以接受任何一个子类的对象，从而用这个父类的对象变量来调用子类中重写的方法而输出不同结果
 *  **/
class People2 {
  public name: string
  public eat() {
    console.log('People父类的eat')
  }
}
class AmericanPeople extends People2 { // 美国人
  public name: string
  public eat() {
    console.log('用叉子吃饭')
  }
}
class ChinesePeople extends People2 { // 中国人
  public name: string
  public eat() {
    console.log('用筷子吃饭')
  }
}
class TuzhuPeople extends People { // 土著人
  public name: string
  public eat() {
    console.log('用手吃饭')
  }
}
// 父类的对象变量people可以接受任何一个子类的对象，例如可以接受AmericanPeople、ChinesePeople、TuzhuPeople
let people2: People2 = new AmericanPeople();
// 从而用这个父类的对象变量来调用子类中重写的方法而输出不同结果
people2.eat() // 用叉子吃饭
people2 = new ChinesePeople()
people2.eat() // 用筷子吃饭
people2 = new TuzhuPeople()
people2.eat() // 用手吃饭